<?php

	/**
	 * @see Bike_Js_VarPart_Func
	 */
	require_once 'Bike/Js/VarPart/Func.php';
	
	
	class Bike_Js_Func extends Bike_Js_VarPart_Func
	{
		static protected $_partOffset = 0;

		protected function initDefaultSettings()
		{
			parent::initDefaultSettings();

			$this->setSettings(array(
				'args' => array(),
				'body' => '',
				'bodyAdapter' => '',
				'bodyDebugCode' => '',
			));
		}

		protected function _makeOptions(array $Args=null)
		{
			$options = array();
			$argsCount = sizeof($Args);
			if($argsCount == 1 && is_array($Args[0]))
			{
				$options = $Args[0];
			}
			elseif($argsCount >= 1)
			{				$options['args'] = $Args;
			}
			return $options;
		}

		protected function getArgs()
		{
			$args = array();
			foreach((array)$this->_settings['args'] as $key => $value)
			{
				$args[$key] = $this->_prepareValue($value);
			}
			return $args;
		}

		public function _args()
		{
			$this->args = func_get_args();
			return $this;
		}

		public function getOmitSettings()
		{
			return array_merge(parent::getOmitSettings(), array('bodyAdapter', 'bodyDebugCode'));
		}

		public function processGetBodyDebugCode($Value)
		{			if(!$Value instanceof Bike_Js_CodeContainer && $Value != '')
			{
				$Value = $this->js()->CodeContainer($Value);
			}
			return $Value;
		}

		public function processGetBodyAdapter($Value)
		{
			if(!$Value instanceof Bike_Js_CodeContainer && $Value != '')
			{
				$Value = $this->js()->CodeContainer($Value);
			}
			return $Value;
		}

		public function processGetBody($Value)
		{
			if(!is_array($Value))
			{
				$Value = array($Value);
			}
			
			$params = $this->_prepareSettings('bodyAdapter', 'bodyDebugCode');
			
			if($this->isDebug())
			{
				array_unshift($Value, $params->bodyDebugCode);
			}
			if($params->bodyAdapter)
			{
				array_unshift($Value, $params->bodyAdapter);
			}
			return $Value;
		}
	}
